from pyspark import SparkConf, SparkContext

if __name__ == '__main__':
    # 构建SparkConf对象
    conf = SparkConf().setAppName("test").setMaster("local[*]")
    # 构建SparkContext执行环境入口对象
    sc = SparkContext(conf=conf)

    rdd = sc.parallelize(range(1, 10)) # 1-9

    result = rdd.reduce(lambda a, b: a + b)
    print(result)
    """
    reduce: 将RDD数据集按照传入函数进行聚合
    """
    # 输出结果 45
